package io.xccit.aischool.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.xccit.aischool.entity.Admin;
import io.xccit.aischool.service.IAdminService;
import io.xccit.aischool.util.MD5;
import io.xccit.aischool.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author CH_ywx
 * @date 2023-06-06
 * @description
 */
@Api(tags = "管理员接口")
@RestController
@RequestMapping("/sms/adminController")
public class AdminController {

    @Autowired
    private IAdminService adminService;

    @ApiOperation("分页查询管理员信息")
    @GetMapping("/getAllAdmin/{pageNo}/{pageSize}")
    public Result<Page<Admin>> getAdminPage(@ApiParam("当前页") @PathVariable Integer pageNo,
                                            @ApiParam("当前页") @PathVariable Integer pageSize,
                                            @ApiParam("管理员姓名-模糊查询对象") String adminName
                                            ){
        Page<Admin> adminPage = new Page<>(pageNo, pageSize);
        return Result.ok(adminService.getAdminPage(adminPage,adminName));
    }

    @ApiOperation("管理员添加/信息修改")
    @PostMapping("/saveOrUpdateAdmin")
    public Result<Boolean> saveOrUpdate(@RequestBody Admin admin){
        admin.setPassword(MD5.encrypt(admin.getPassword()));
        return Result.ok(adminService.saveOrUpdate(admin));
    }
}
